package com.sskj.gcc.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.gcc.ui.activity.ChargeMoneyActivity;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.ChargeCoinItemBean;
import com.sskj.gocoin.m.bean.RechargeInfoBean;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;

public class ChargeMoneyActivityPresenter extends BasePresenter<ChargeMoneyActivity> {
    public void requestUserAssetList() {
        OkGo.<HttpData<List<ChargeCoinItemBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData<List<ChargeCoinItemBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<ChargeCoinItemBean>>> response) {
                        HttpData<List<ChargeCoinItemBean>> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.onDataSuccess(httpListData.getData());
                        }
                    }
                });
    }

    public void recharge(int assetId) {
        OkGo.<com.sskj.gocoin.m.bean.HttpData<RechargeInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.RECHARGE_URL)
                .params("type", assetId)
                .execute(new com.sskj.gocoin.m.http.JsonCallBack<com.sskj.gocoin.m.bean.HttpData<RechargeInfoBean>>(this) {
                    @Override
                    public void _onSuccess(Response<com.sskj.gocoin.m.bean.HttpData<RechargeInfoBean>> response) {
                        com.sskj.gocoin.m.bean.HttpData<RechargeInfoBean> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.updateView(httpListData.getData());
                        } else {
                            ToastUtil.showShort(httpListData.getMsg());
                        }
                    }
                });
    }

}
